package com.tedu.spring.boot.demo1.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tedu.spring.boot.demo1.entity.pojo.User;
import com.tedu.spring.boot.demo1.entity.pojo.Weibo;
import com.tedu.spring.boot.demo1.entity.vo.WeiboVO;
import com.tedu.spring.boot.demo1.mapper.UserMapper;
import com.tedu.spring.boot.demo1.mapper.WeiboMapper;
import com.tedu.spring.boot.demo1.service.WeiboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Author：毕龙
 * Date: 2024/8/29 15:30
 */
@Service
public class WeiboServiceImpl implements WeiboService {

    @Autowired
    private WeiboMapper weiboMapper;

    @Autowired
    private UserMapper userMapper;

    public List<WeiboVO> listWeibo(){
        List<Weibo> list = weiboMapper.selectList(null);

        ArrayList<WeiboVO> vos = new ArrayList<>();
        WeiboVO vo = null;
        for (int i = 0; i < list.size(); i++) {
            vo = new WeiboVO();
            BeanUtils.copyProperties(list.get(i),vo);
            Integer id = list.get(i).getUserId();
            QueryWrapper<User> wrapper = new QueryWrapper<>();
            wrapper.eq("id",id);
            User user = userMapper.selectOne(wrapper);
            vo.setNickname(user.getNickname());
            vos.add(vo);
        }
        System.out.println(vos);
        return vos;
    }


}
